import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.getAllpickingList(this);
		//获取下拉框
		this.getPickingselect(this);
	},
	mounted() {
		
	},
	activated() {
		this.getAllpickingList(this);
	},
	methods: {
		//获取列表接口
		getAllpickingList(that,params,pageIndex = 1,pageSize = 10) {
			params = params || {businessType:20};
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/supplier/whWarehouse/list',
				//url:'/api/supplier/whWarehouse/list',
				data:{
					condition:params,
					pageIndex: pageIndex,
					pageSize: pageSize,
				}
			}).then((res)=>{
				that.Model.tableData = [];
				var data = res.data;
				if(data.status == 200){
					var obj = {};
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					var result = data.result.result;
					if(result){
						for (var i = 0; i < result.length; i++) {
							obj = objDeepCopy(result[i]);
							console.log(obj);
							that.Model.tableData.push(obj);
						}
					}
				}else{
					that.tips(that,'warning',data.msg)
				}
			
			});
		},
		ToPage() {
			this.$router.push({
				name: 'receiveMaterialLeaveWarehouse',
			})
		},
		//下拉框
		getPickingselect(that) {
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/supplier/whWarehouse/getDropBox/203',
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){
					var result = data.result;
					 console.log(result)
					this.Model.filterOptionData = result;
					let wareHouseTypeArr = [], leavewareHouseStatusArr = [], supplierArr = [];
					for (let i in result.wareHouseType) {//出库单类型
						wareHouseTypeArr.push({ label: result.wareHouseType[i], value: i });
					};
					for (let i in result.wareHouseStatus) {//出库单状态
						leavewareHouseStatusArr.push({ label: result.wareHouseStatus[i], value: i });
					};
					for (let i in result.supplier) {//供应商
						supplierArr.push({ label: result.supplier[i], value: i });
					};
					this.Model.filterOption.items[1].data = wareHouseTypeArr;//出库单类型
					this.Model.filterOption.items[2].data = leavewareHouseStatusArr;//出库单状态
					this.Model.filterOption.items[4].data = supplierArr;//供应商
					this.Model.defaultFilterOption = _.cloneDeep(this.Model.filterOption);
				}else{
					that.tips(that,'warning',data.msg)
				}
			
			});
		},
		//导出
		toExportExcel() {
			if(this.Model.TableSelectDataStr){
				window.open('/api/supplier/common/exportExcel?name=materialsOut&idList='+this.Model.TableSelectDataStr);
			}else{
				this.tips(this,'warning','请先勾选导出条目');
			}
		},
		tableDetail(row,flag,status) {
			this.$router.push({
				path:'receiveMaterialDetail',
				query: {
					id:row.number,
					flag,
					status
				}
			});
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			// 选中的数组
			this.Model.TableSelectData = val;
			var arr = '';
			for (var i = 0; i < val.length; i++) {
				arr += val[i].id+',';
			}
			arr = arr.substr(0, arr.length - 1);  
			this.Model.TableSelectDataStr = arr;
		},
		handleCurrentChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllpickingList(this,searchFromData,val);
		},
		handleSizeChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllpickingList(this,searchFromData,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = {
				businessType:20,
				keyword:val.keyword,
				type:val.type,
				status:val.status,
				processingType:val.processingType,
				supplierCode:val.supplierCode,
				operaterId:val.operaterId
			}
			if(val.createTime){
				this.Model.searchFromData.createTimeStart = getDateString(val.createTime[0]);
				this.Model.searchFromData.createTimeEnd = getDateString(val.createTime[1]);
			}
			if(val.storageTime){
				this.Model.searchFromData.storageTimeStart = getDateString(val.storageTime[0]);
				this.Model.searchFromData.storageTimeEnd = getDateString(val.storageTime[1]);
			}
			console.log(this.Model.searchFromData)
		},
		toSearch(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllpickingList(this,searchFromData);
			console.log(searchFromData)
		},
		toClear(val) {
			this.Model.searchFromData = _.cloneDeep(this.Model.defaultSearchFromData);
			this.Model.filterOption = _.cloneDeep(this.Model.defaultFilterOption);
		},
		toExport(val) {
			console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	}
}
export default Controller;